Skip to main content

LGBM with cuda cores

Cell 1:

Clone the LightGBM repository from GitHub

!git clone --recursive https://github.com/microsoft/LightGBM 

cell-1

Cell 2:

#Navigate to the LightGBM directory


%cd ./LightGBM/


# Remove existing build directory and create a new one

!rm -rf ./build
!mkdir build
%cd ./build



# Configure CMake to build LightGBM with CUDA support
!cmake -DUSE_CUDA=1 ..


#Compile LightGBM with multiple threads:
!make -j4


#Go back to the LightGBM directory:


%cd ..


#Install LightGBM with precompiled CUDA support:


!sh ./build-python.sh install --precompile --gpu

cell-2

tip

After first, Second cell, select runtime > restart runtime and run cell 3.

cell-2

Cell 3:

import lightgbm as lgb
import numpy as np
import pandas as pd
from sklearn.datasets import make_regression

X, y = make_regression(n_samples=10_000)
dtrain = lgb.Dataset(X, label=y)
lgbm_train = lgb.Dataset(X, label=y)

params={"objective": "regression",
"device": "cuda"}
model = lgb.train(params, lgbm_train)

cell-3